package com.hongshu.idle.controller.idle;

import com.hongshu.common.core.enums.Result;
import com.hongshu.common.core.validator.myVaildator.noLogin.NoLoginIntercept;
import com.hongshu.idle.domain.entity.IdleUserAddress;
import com.hongshu.idle.service.idle.IIdleUserAddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 地址
 *
 * @author: hongshu
 */
@RequestMapping("/address")
@RestController
public class IdleUserAddressController {

    @Autowired
    private IIdleUserAddressService addressService;


    /**
     * 获取地址列表
     */
    @GetMapping("addressList")
    @NoLoginIntercept
    public Result<?> getAddressList(String uid) {
        List<IdleUserAddress> addressList = addressService.getAddressList(uid);
        return Result.ok(addressList);
    }

    /**
     * 获取地址
     *
     * @param id 地址ID
     */
    @GetMapping("getAddress")
    @NoLoginIntercept
    public Result<?> getAddressById(String id) {
        IdleUserAddress address = addressService.getAddressById(id);
        return Result.ok(address);
    }

    /**
     * 新增地址
     *
     * @param addressData 地址对象
     */
    @PostMapping("saveAddress")
    public Result<?> saveAddress(@RequestParam("addressData") String addressData) {
        addressService.saveAddress(addressData);
        return Result.ok();
    }

    /**
     * 更新地址
     *
     * @param addressData 地址对象
     */
    @PostMapping("updateAddress")
    public Result<?> updateAddress(@RequestParam("addressData") String addressData) {
        addressService.updateAddress(addressData);
        return Result.ok();
    }

    /**
     * 删除地址
     *
     * @param id 地址对象
     */
    @PostMapping("deleteAddress")
    public Result<?> deleteAddress(String id) {
        addressService.deleteAddress(id);
        return Result.ok();
    }

}
